package major;

import org.apache.kafka.clients.consumer.*;

import java.time.Duration;
import java.util.Arrays;

public class ObserverMing {
    public static void main(String[] args) {
        Consumer<String, String> consumer = new ConsumerBuilder("XiaoMing",
                Arrays.asList("grey")).build();
        while (true){
            ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(10));
            for (ConsumerRecord<String, String> record : records) {
                Integer age ;
                try{
                    age = Integer.parseInt(record.value());
                }catch (Exception e){
                    age=18;
                }
                String s = String.format("妹妹今年%d岁，同时哥哥小明今年%d岁", age,age+6);
                System.out.println(s);
            }
        }
    }
}
